package com.zeta.eduservice.service.impl;

import com.zeta.eduservice.entity.EduTeacher;
import com.zeta.eduservice.entity.vo.TeacherQuery;
import com.zeta.eduservice.mapper.EduTeacherMapper;
import com.zeta.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author zeta
 * @since 2020-07-29
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
	@Override
	public boolean removeById1(Serializable id) {
	    Integer result = baseMapper.deleteById(id);
	    return null != result && result > 0;
	}
	@Override
	public Map<String, Object> pageListWeb(Page<EduTeacher> pageParam) {

	    QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
	    queryWrapper.orderByAsc("sort");

	    baseMapper.selectPage(pageParam, queryWrapper);

	    List<EduTeacher> records = pageParam.getRecords();
	    long current = pageParam.getCurrent();
	    long pages = pageParam.getPages();
	    long size = pageParam.getSize();
	    long total = pageParam.getTotal();
	    boolean hasNext = pageParam.hasNext();
	    boolean hasPrevious = pageParam.hasPrevious();

	    Map<String, Object> map = new HashMap<String, Object>();
	    map.put("items", records);
	    map.put("current", current);
	    map.put("pages", pages);
	    map.put("size", size);
	    map.put("total", total);
	    map.put("hasNext", hasNext);
	    map.put("hasPrevious", hasPrevious);

	    return map;
	}
	@Override
	public List<EduTeacher> getByclass(Page<EduTeacher> page, TeacherQuery searcherObj) {
		List<EduTeacher> byClassId = baseMapper.getByClassId(page, searcherObj.getClassId());
		return byClassId;
	}

}
